#ifndef MAININTERFACE_H
#define MAININTERFACE_H

#include <QMainWindow>
#include"mainwindow.h"
#include"serialportconnection.h"
#include"modbusmanger.h"
#include"usermanagement.h"
#include <QButtonGroup>
#include "sensordatadisplayinterface.h"
#include "dynamiccurvedisplayinterface.h"
#include"deviceserialportcontrol.h"
#include "serialportset.h"
#include"timeparameterset.h"
#include "logrecord.h"
namespace Ui {
class MainInterface;
}
struct deviceStatusDataBlock
{
bool mainSwitch_LED;//1
bool IrrigationEquipment_LED;//2
bool ventilatingEquipment_LED;//3
bool CO2Interpolator_LED;//4
bool rollUpDoor_LED;//5
bool lightingEquipment_LED;//6
bool heatingEquipment_LED;//7
bool airCooler_LED;//8
bool warningLed;//9
};
struct warningSmallLED
{
bool warning_CO2;
bool warning_Light;
bool warning_AirT;
bool warning_AirH;
bool warning_SoilH;

};
struct sensorData;
class MainInterface : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainInterface(QWidget *parent = nullptr);
    ~MainInterface();
friend class MainWindow; //设置MainWindow为MainInterface的 友元声明

   sensorData sensorDataSet;
static MainInterface* instance();
signals:
    void returnToParentSignal();// 定义返回信号
    void sendMosimDeviceSwitchStatus(bool ModsimDeviceSwitch);
    void sendMainSwitchStatus(bool MainSwitch);
    void sendMainSwitchEnabel();
    void sendAlarmTipSound();//发送播放系统警报音的信号
    //void sendLcdNumberDisplay(bool MainSwitch);


    void  sendPushbuttonG1_1(bool status);//发送G1按钮对的信号空气湿度+
    void  sendPushbuttonG1_2(bool status);//发送G1按钮对的信号土壤湿度+

    void  sendPushbuttonG2_1(bool status);//发送G2按钮对的信号//空气湿度-
    void  sendPushbuttonG2_2(bool status);//发送G2按钮对的信号//CO2浓度-
    void  sendPushbuttonG2_3(bool status);//发送G2按钮对的信号//土壤湿度-
     void  sendPushbuttonG3(bool status);//发送G3按钮对的信号 CO2+
    void  sendPushbuttonG4(bool status);//发送G4按钮对的信号光照-
    void  sendPushbuttonG5(bool status);//发送G5按钮对的信号光照+

    void  sendPushbuttonG6(bool status);//发送G6按钮对的信号温度+
    void  sendPushbuttonG7(bool status);//发送G7按钮对的信号温度-
    void sendAutoControl(bool status);//关闭自动控制;true为打开，false为关闭
    void sendDisConnectDevice();//发送串口断联信号

 private slots:
    void on_pushButton_Back_clicked();
    void returnToParent();//子类向父类发送返回信号
    void on_pushButton_12_clicked();
    void qTiemrDisplayData();
     void LcdNumberDispaly();
    bool linkingDevice(bool index=true);//连接模拟设备的modsim




    void on_pushButtonMainSwitch_clicked();

    void on_radioButtonG1_1_clicked();

    void on_radioButtonG1_2_clicked();

    void on_pushButtonCtrlMode_clicked();

    void on_radioButtonG2_1_clicked();

    void on_radioButtonG2_2_clicked();

    void on_radioButtonG3_1_clicked();

    void on_radioButtonG3_2_clicked();

    void on_radioButtonG4_1_clicked();

    void on_radioButtonG5_1_clicked();

    void on_radioButtonG5_2_clicked();

    void on_radioButtonG7_1_clicked();

    void on_radioButtonG6_1_clicked();

    void on_radioButtonG6_2_clicked();

    void on_radioButtonG7_2_clicked();

    void on_radioButtonG4_2_clicked();

    void on_logOutPushButton_S_clicked();

    void on_userListPushButton_S_clicked();

    void on_pushButtonHistoryData_clicked();

    void on_pushButtonSerialPortConfirm_clicked();

    void on_dynamicCurvePushButton_S_clicked();
    void refreshDeviceStatusLEDONorOff(int index,bool status);


    void on_pushButtonModsimDeviceSwitch_clicked();

    void on_switchUserPushButton_S_clicked();



    void on_warningPushButton_S_clicked();

    void on_parameterSetingPushButton_S_clicked();

    void on_timePushButton_S_clicked();

    void on_logPushbutton_S_clicked();
    void on_pidParameterSetPushbutton_S_clicked();//pid参数设置
    void warningLed(bool ok);
   void warningAirTLED(int status);//用来改变温度警告灯 1高温 -1低温 0正常
   void warningAirHLED(int status);
   void warningLightLED(int status);
   void warningCO2LED(int status);
   void warningSoilHLED(int status);
   //自动控制
   void autoControlAirTemperatureDeviceLED(int index);
   void closeAirTemperatureDeviceLED();
   void closeAirTemperatureDeviceLEDNormal();

   void autoControlLightIntensityDeviceLED(int index);
   void closeLightIntensityDeviceLED();
   void closeLightIntensityDeviceLEDNormal();

   void autoControlAirHumidityDeviceLED(int index,int selectIndex);//湿度控制
   void closeAirHumidityDeviceLED();
   void closeAirHumidityDeviceLEDNormal();




   void autoControlCO2ConcentrationDeviceLED(int index,int selectIndex);//CO2浓度控制
   void closeCO2ConcentrationDeviceLED();
   void closeCO2ConcentrationDeviceLEDNormal();

   void autoControlSoilMoistureDeviceLED(int index,int selectIndex);//土壤湿度控制
   void closeSoilMoistureDeviceLED();
   void closeSoilMoistureDeviceLEDNormal();

   void on_SQLPushButton_S_clicked();

   void on_ModSim32PushButton_S_clicked();

private:
    bool isNormal;//存储灯的状态没用
    QTimer *m_timer_View;//定义定时器
    int i;//测试重要
//  bool mainSwitchStatus;
    bool ctrlMode;//控制模式
    QTimer *AutoTimer[5];//0 1 2 3 4---->0为温度定时器
    int deviceIndex[5];
warningSmallLED smallLED;
bool ModSim32Status=false;//存储ModSim32的开关状态
QProcess *modsimProcess ;
private:
    Ui::MainInterface *ui;
    void connectSerialPort(bool status);
    void initWarningLight();
    void initDeviceStatusLED();
    void initQStatusBar();//初始化状态栏
    void setPushbuttonStatus();
    void initdeviceStatusDataBlock();//初始化设备状态数据块
    void initCtrlMode();
    void initRadioPushbutton();
    void setRadioCheckabel(bool CtrlMode);
    void setDeviceStatusLEDONorOff(deviceStatusDataBlock &Data,int index=0,bool ok=true);
    void setDeviceStatusDataBlock(bool ok);//设置数据块
    void turnOffDeviceDisplay();

//    bool setSystemPort();
     void initWarningSmallLED(warningSmallLED&smallLED);
     void setWarningSmallLEDStatus(warningSmallLED&smallLED,int index=0,bool ok=true);//正常和异常
     void initAutoTimer();//初始化自动控制设备的定时器
     void initSelectIrrAndVan();//初始化灌溉设备和通风设备为none
     void setPidSetPointValue(int id=-1);
     void setQlcdNumberColor(int index=0,bool status=true,bool set=true);
     void setPidQlcdNumberColor();
     void setMainSwitchStatus();
     void setPushButtonStyleSheet();
     void launchModSim32();//启动ModSim32
     void closeModSim32();//关闭ModSim32
     void initModSimProcess();
     void setModSim32PushButton(bool Status);
};

#endif // MAININTERFACE_H
